package com.yuntcm.group6.med_booking.controller;

import com.yuntcm.group6.med_booking.entity.Patient;
import com.yuntcm.group6.med_booking.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/patient")
public class PatientController {

    @Autowired
    private PatientService patientService;

    @GetMapping
    public List<Patient> patientList() {
        return patientService.listAllPatients();
    }

    @PostMapping("/update")
    public boolean updatePatient(@RequestBody Patient patient) {
        return patientService.updateById(patient);
    }

    @DeleteMapping("/delete/{id}")
    public boolean deletePatient(@PathVariable Long id) {
        return patientService.removeById(id);
    }

    @PostMapping("/add")
    public boolean addPatient(@RequestBody Patient patient) {
        return patientService.save(patient);
    }
}